# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=pyparsing
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.4.4
pkgrel=1
pkgdesc='General parsing module for Python (mingw-w64)'
arch=('any')
url='https://pyparsing.wikispaces.com/'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
source=("https://github.com/pyparsing/pyparsing/archive/pyparsing_$pkgver.tar.gz")
sha512sums=('64c127fd3df3b09c7cbaa4819c42e00e5aea04543b0f3346fdab2c0fae6c6df449937d8ceb18ababf08ac86d8385985494dc386b412c576ecf4dac5f8d56f44e')

prepare() {
  cd "$srcdir"/
  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${_realname}_${pkgver}" "python${pver}-build-${CARCH}"
  done  
}

build() {
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check() {
  for pver in {2,3}; do
    msg "Python ${pver} test for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} unitTests.py
  done
}
package_python3-pyparsing() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd ${srcdir}/python3-build-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

package_python2-pyparsing() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd ${srcdir}/python2-build-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

package_mingw-w64-i686-python2-pyparsing() {
  package_python2-pyparsing
}

package_mingw-w64-i686-python3-pyparsing() {
  package_python3-pyparsing
}

package_mingw-w64-x86_64-python2-pyparsing() {
  package_python2-pyparsing
}

package_mingw-w64-x86_64-python3-pyparsing() {
  package_python3-pyparsing
}
